<style>

</style>

<template>
  <div class="panel">
    <!--搜索框-->
    <div class="panel-border">
      <SearchForm
        ref="mychild"
        size="mini"
        :search-data="searchData"
        :search-form="searchForm"
        :search-handle="searchHandle"
      />
    </div>
    <!--表格-->
    <div class="panel-border">
      <button class="customize-add" @click="editQuest(null , 'add')">
        <img src="../../images/add.png">
        {{ $t('add') }}
      </button>

      <el-table
        v-loading="loading"
        :data="optionData"
        :border="true"
        :show-header="true"
        :stripe="true"
      >
        <el-table-column
          type="index"
          label="序号"
          width="50"
        />
        <el-table-column
          v-for="(table, index) in tableLabel"
          :key="index"
          :prop="table.prop"
          :label="table.label"
        >
          <template slot-scope="scope">
            <span v-if="table.prop == 'isShare'">
              <span v-if="scope.row[table.prop] == '1'">
                共享
              </span>
              <span v-if="scope.row[table.prop] == '0'">
                私有
              </span>
            </span>
            <span v-else>
              {{ scope.row[table.prop] }}
            </span>
          </template>
        </el-table-column>
        <!--名称特殊处理-->
        <el-table-column
          fixed="right"
          label="操作"
          width="150"
        >
          <template slot-scope="scope">
            <el-button type="text" size="small" @click="editQuest(scope.row.questionId , 'edit')">编辑</el-button>
            <el-button type="text" size="small" @click="deleteBtn(scope.row.questionId)">删除</el-button>
            <el-button type="text" size="small" @click="editQuest(scope.row.questionId , 'copy')">复制</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--分页-->
      <pagination :page="page" />
    </div>
    <el-dialog
      :before-close="dialogClose"
      :fullscreen="isDetail"
      :visible.sync="isDetail"
      :append-to-body="true"
      :close-on-click-modal="false"
    >
      <operating :edit-id="editId" :edit-type="editType" :show-cell-data="showCellData" @ondialogClose="isDetail=false, getData()" />
    </el-dialog>

  </div>
</template>

<script>
import SearchForm from '../../components/search-filter/searchForm'
import pagination from '../../components/pagination/pagination'
import operating from './operating'

export default {
  name: 'Question',
  components: {
    SearchForm,
    pagination,
    operating
  },
  data() {
    return {
      editId: null,
      editType: 'edit',
      isDetail: false,
      showCellData: [],
      // 数据展示
      loading: false,
      tableLabel: [
        { label: '本地网', prop: 'lanIdText' },
        { label: '问题名称', prop: 'questionName' },
        { label: '问题类型', prop: 'questionTypeText' },
        { label: '调研引用次数', prop: 'referCount' },
        { label: '创建人', prop: 'createStaffName' },
        { label: '创建时间', prop: 'createDate' },
        { label: '权限', prop: 'isShare' }
      ],
      optionData: [],
      // 查询表单
      searchData: {
        questionType: '',
        isShare: '',
        questionName: ''
      },
      searchForm: [
        { type: 'Checkbox', label: '问题类型:', prop: 'questionType', datas: [] },
        { type: 'Checkbox', label: '权限:', prop: 'isShare', datas: [] },
        { type: 'Input', label: '问题名称:', prop: 'questionName', placeholder: '请输入问题名称' }
      ],
      searchHandle: [
        { label: '查询', search: 'query', type: 'primary', handle: () => this.onSearch() },
        { label: '重置', search: 'reset', type: 'primary', handle: () => this.onReset() }
      ],
      // 翻页
      page: {
        total: 100,
        limit: 10,
        pageSize: 10,
        pagerCount: 5,
        currentPage: 1,
        pageTo: () => this.getData()
      },
      pageInit: {
        total: 0,
        limit: 10,
        pageSize: 10,
        pagerCount: 1,
        currentPage: 1,
        pageTo: () => this.getData()
      },
      params: {},
      pageInfo: {
        pageIndex: 1,
        pageSize: 10
      }
    }
  },
  created() {
    // 初始化
    this.init()
  },
  methods: {
    init() {
      this.search()
      this.getData()
    },
    search() {

      // this.$router.push({ path: '/questionair'});/

      // var dataArray = [];
      // var dataJson = {};
      // dataJson.item_text = "共享";
      // dataJson.item_code = "1";
      // dataArray.push(dataJson)
      // this.U.setSearchForm(this.searchForm , "isShare" , dataArray);

      // this.R.forQuest.getDict('QUESTION_TYPE').then((res) => {
      //     console.log(res)
      //     if (res.ok) {
      //     }
      // });
    },
    pageTo(pageIndex, size) {
      this.page.limit = size
      this.page.offset = pageIndex
      this.getData()
    },
    getData() {
      const that = this
      that.loading = true
      this.pageInfo.pageSize = this.page.pageSize
      this.pageInfo.pageIndex = this.page.currentPage
      this.params.pageInfo = this.pageInfo
      this.R.forQuest.postJson('/question/qryMktQuestionList', this.params).then(res => {
        if (res.ok) {
          that.page.total = res.resultObject.pageInfo.rowCount
          that.page.currentPage = res.resultObject.pageInfo.pageIndex
          that.page.pageSize = res.resultObject.pageInfo.pageSize
          that.page.pagerCount = res.resultObject.pageInfo.pageCount
          that.optionData = res.resultObject.mktQuestions
          that.loading = false
        }
      })
    },
    dialogClose(done) {
      done()
      this.isDetail = false
      this.editId = null
      this.editType = 'edit'
      this.getData()
    },
    onSearch() {
      this.pageInfo = this.searchData
      this.page = this.pageInit
      this.page.currentPage = 1
      this.getData()
    },
    onReset() {
      this.searchData.questionType = ''
      this.searchData.isShare = ''
      this.searchData.questionName = ''
      this.pageInfo = {}
      this.page = this.pageInit
      this.page.currentPage = 1
      this.getData()
    },
    deleteBtn(id) {
      if (!id) {
        this.$message.error('删除时id不能为空')
        return
      }

      this.$confirm('确认删除？')
        .then(() => {
          this.params = {}
          this.params.questionId = id
          this.R.forQuest.postJson('/question/delContactEvt', this.params).then(res => {
            if (res.ok) {
              this.getData()
            }
          }).catch(err => {
            this.$message.error(err.toString())
          })
        }).catch(() => {})
    },
    editQuest(questId, type) {
      console.log(questId + '传递id')
      this.editId = questId
      this.editType = type
      this.showCellData = []
      this.isDetail = true
    },
    copyBtn() {

    }
  }
}
</script>
